/**
 * QuestionController
 *
 * @description :: Server-side logic for managing questions
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

module.exports = {

	findOrDelete: function (req, res, next) {
		//console.log('question find or delete function is working as planned')
		var question = req.params.all()
		//console.log('logging unique id')
		//console.log(question.unique_id)
		Question.findOne({unique_id: question.unique_id})
		.exec(function findCb(err, found){
			if (err){console.log(err)}
			if (found){
				Question.destroy({unique_id: question.unique_id})
				.exec(function cb(err, deleted){
					if (err){console.log(err)}
					console.log(deleted)
					for (var i = 0; i < question.answers.length; i++){
						QuestionChoice.destroy({unique_id: question.answers[i].unique_id})
						.exec(function cb2(err, deleted){
							if (err){console.log(err)}
						})
					}
				res.status(200);
				res.json(deleted);
				})
			}
		})
	}
	
};

